package me.xiaoyan.ehr.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import me.xiaoyan.ehr.mapper.CheckRecordMapper;
import me.xiaoyan.ehr.po.CheckRecord;
import me.xiaoyan.ehr.service.CheckRecordService;
import me.xiaoyan.ehr.util.StringUtil;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CheckRecordServiceImpl extends BaseService<CheckRecordMapper, CheckRecord> implements CheckRecordService {
    @Override
    public List<CheckRecord> getTodayRecord(Integer empId) {
        QueryWrapper query = new QueryWrapper();
        query.eq("record_date", StringUtil.formatDate("dd"));
        query.eq("record_month", StringUtil.formatDate("yyyyMM"));
        query.eq("employee_id",empId);
        return list(query);
    }

    @Override
    public List<CheckRecord> getCurrentMonthRecords(Integer empId){
        return getMonthRecords(empId,StringUtil.formatDate("yyyyMM"));
    }

    @Override
    public List<CheckRecord> getMonthRecords(Integer empId, String month) {
        QueryWrapper query = new QueryWrapper();
        query.eq("record_month", month);
        query.eq("employee_id",empId);
        query.orderByDesc("id");
        return list(query);
    }

    @Override
    public void sign(Integer employeeId, String type) {
        CheckRecord record = new CheckRecord();
        record.setEmployeeId(employeeId);
        record.setAction(type);
        record.setRecordTime(new Date());
        save(record);
    }
}
